package com.rongke.web.quartz;


import com.rongke.service.BuyTogetherUserService;
import com.rongke.service.ExperienceGoodsService;
import com.rongke.service.OrdersService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 开启定时
 * Created by bin on 2016/12/6.
 */
@Service
@Transactional
public class WorkorderCheckJobPerDay extends QuartzJobBean {

    private final Logger log = LoggerFactory.getLogger(getClass());
    private static boolean isRun = false;

    protected void executeInternal(JobExecutionContext executionContext) throws JobExecutionException {
        if (isRun) {
            System.out.println("前一次未执行完,跳过本次任务!");
            return;
        }
        isRun = true;
        task(executionContext);
        isRun = false;
//        System.out.println("执行逻辑-isRunFinish");

    }

    private void task(JobExecutionContext executionContext) {
        try {
            ApplicationContext applicationContext = (ApplicationContext) executionContext.getScheduler().getContext().get("applicationContext");
           log.debug("每日一次定时任务");

            log.debug("******************执行收货后15天内未填写调查问卷发消息提醒*******************");
            ExperienceGoodsService experienceGoodsService = applicationContext.getBean(ExperienceGoodsService.class);
            experienceGoodsService.noticeToFillQuestionaire();

            //            订单七天后没有没确认收货  自动确认收货 晚上十二点后执行
            OrdersService ordersService = (OrdersService) applicationContext.getBean(OrdersService.class);
            log.debug("******************执行7天自动确认收货*******************");
            ordersService.orderTask();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String agrs[]) {
        try {

            Calendar calendar = Calendar.getInstance();
            calendar.set(2017, 3, 2, 0, 1, 0);
            Date date = calendar.getTime();
            Date str = new SimpleDateFormat("HH:mm:ss").parse(new SimpleDateFormat("HH:mm:ss").format(date));
            System.out.print(str);
            if (new SimpleDateFormat("HH:mm:ss").parse("00:01:59").getTime() > str.getTime()) {
                System.out.print("aaaaaa");
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        ;
    }


}
